package com.example.jetpack;

import android.graphics.Color;
import android.text.TextUtils;
import android.widget.ImageView;

import androidx.databinding.BindingAdapter;

import com.bumptech.glide.Glide;

public class ImageLoaderUtil {

    //图片Adapter需要指定 @BindingAdapter("image")，并且这个方法必须是静态的
    @BindingAdapter(value = {"image","defaultImageResource"},requireAll = false)
    public static void setImage(ImageView imageView,String url,int redId){
        if(!TextUtils.isEmpty(url)){
            Glide.with(imageView.getContext()).load(url).into(imageView);
        }else {
            imageView.setImageResource(redId);
        }
    }
}
